package com.yunxin.yundubbo.mode;

import com.alibaba.fastjson2.JSON;
import lombok.Data;

@Data
public class Message{

    private short version;

    private short magic;

    private int length;

    private short type;

    private byte[] bytes;

    public static Message send(String className,String data,String method,String requestId){
        Message message = new Message();
        Buffer buffer = new Buffer();
        buffer.setClassName(className);
        buffer.setData(data);
        buffer.setMethod(method);
        buffer.setRequestId(requestId);
        message.setType((short) 1);
        message.setMagic((short) 1);
        message.setVersion((short) 2);
        message.setBytes(JSON.toJSONString(buffer).getBytes());
        message.setLength(message.getBytes().length);
        return message;
    }
}
